package pers.hl.library

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.simple.eventbus.Subscriber
import pers.hl.lib_global.arouter.RouterPath
import pers.hl.lib_global.common.Const
import pers.hl.lib_global.common.MMKVHelper
import pers.hl.lib_global.common.RouteUtils

class RouteActivity : AppCompatActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val user = MMKVHelper.getUser()
        if (user == null) {
            navToLogin()
            finish()
            return
        }
        if (user.isAdmin()) {
            navToAdmin()
            finish()
        } else {
            navToMain()
            finish()
        }
    }

    private fun initEvent() {
//        button1.setOnClickListener{
//            navToMain()
//        }
//        button2.setOnClickListener {
//            navToLogin()
//        }
    }

    private fun navToMain() {
        RouteUtils.nav(RouterPath.main)
    }

    private fun navToAdmin() {
        RouteUtils.nav(RouterPath.mainAdmin)
    }

    private fun navToLogin() {
        RouteUtils.nav(RouterPath.login)
    }

    @Subscriber(tag = Const.MessageEvent.EVENT_TOKEN_EXPIRED)
    fun onTokenExpired() {
        navToLogin()
    }


}